/**
 * CastDice.java
 *
 * Created on Apr 30, 2010, 4:44:24 PM
 * 
 * @author Beatrice Bacelli
 * @author Luca Bedogni
 * @author Silvia Righini
 */

package unibo.lsb.graphic;

import java.awt.Component;
import java.awt.Container;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JPanel;

import unibo.lsb.logic.CoveredDice;
import unibo.lsb.logic.LastAssignedPenalty;

public class DoubtOthersDiceDialog extends javax.swing.JDialog {

	private javax.swing.JPanel firstRow;
	private javax.swing.JPanel secondRow;
	private javax.swing.JPanel thirdRow;
	private javax.swing.JPanel fourthRow;
	private javax.swing.JButton btn_ok;
	private javax.swing.JPanel pnl_dice;
	private javax.swing.JLabel lbl_dice1;
	private javax.swing.JLabel lbl_dice2;
	private javax.swing.JLabel lbl_text1;
	private javax.swing.JLabel lbl_text2;

	GameTableWindow parent;
	CoveredDice coveredDice;
	LastAssignedPenalty lastAssignedPenalty;
	int playerWhoGetsPenalty;

	GraphicUtils graphicUtils = new GraphicUtils();

	public DoubtOthersDiceDialog(GameTableWindow parent, boolean modal,
			CoveredDice coveredDice, LastAssignedPenalty lastAssignedPenalty,
			int playerWhoGetsPenalty) {
		super(parent, modal);
		this.parent = parent;
		this.coveredDice = coveredDice;
		this.lastAssignedPenalty = lastAssignedPenalty;
		this.playerWhoGetsPenalty = playerWhoGetsPenalty;
		initComponents();
	}

	private void initComponents() {

		firstRow = new javax.swing.JPanel();
		secondRow = new javax.swing.JPanel();
		thirdRow = new javax.swing.JPanel();
		fourthRow = new javax.swing.JPanel();

		pnl_dice = new javax.swing.JPanel();
		lbl_dice1 = new javax.swing.JLabel();
		lbl_dice2 = new javax.swing.JLabel();

		lbl_text1 = new javax.swing.JLabel();
		lbl_text2 = new javax.swing.JLabel();

		btn_ok = new javax.swing.JButton();

		setTitle("Penalty assignment..");
		setResizable(false);
		setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

		int d1 = (new Integer(coveredDice.getCovered().getFirstDice()))
				.intValue();
		int d2 = (new Integer(coveredDice.getCovered().getSecondDice()))
				.intValue();

		lbl_dice1.setText("");
		lbl_dice1.setIcon(graphicUtils.getDiceIcon(d1));
		lbl_dice2.setText("");
		lbl_dice2.setIcon(graphicUtils.getDiceIcon(d2));

		lbl_text1.setText(MessagesGenerator.xDeclaredDiceButMadeOtherDice(
				MessagesGenerator.PLAYER_OTHER, coveredDice));
		lbl_text2.setText(MessagesGenerator.penaltyForDoubting(
				playerWhoGetsPenalty, lastAssignedPenalty));

		btn_ok.setText("    ok    ");
		// Dimension btn_ok_dim = new Dimension(80, 20);
		// btn_ok.setMinimumSize(btn_ok_dim);
		// btn_ok.setPreferredSize(btn_ok_dim);
		// btn_ok.setSize(btn_ok_dim);
		btn_ok.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				btn_okActionPerformed(evt);
			}
		});

		Container pane = this.getContentPane();
		pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

		pnl_dice.setLayout(new BoxLayout(pnl_dice, BoxLayout.X_AXIS));
		addToContainer(lbl_dice1, pnl_dice);
		addToContainer(lbl_dice2, pnl_dice);

		addToContainer(pnl_dice, pane);
		addToContainer(lbl_text1, pane);
		addToContainer(lbl_text2, pane);
		addToContainer(btn_ok, pane, false);

		/* adds some extra space */
		addToContainer(new JPanel(), pane, false);

		pack();
		setLocationRelativeTo(parent);

	}

	private void addToContainer(JComponent component, Container pane) {
		addToContainer(component, pane, 6, 6, 6, 6, true);
	}

	private void addToContainer(JComponent component, Container pane, boolean b) {
		addToContainer(component, pane, 0, 0, 0, 0, false);
	}

	private void addToContainer(JComponent component, Container pane, int top,
			int left, int bottom, int right, boolean b) {
		if (b) {
			component.setBorder(BorderFactory.createEmptyBorder(top, left,
					bottom, right));
		}
		component.setAlignmentX(Component.CENTER_ALIGNMENT);
		pane.add(component);
	}

	private void btn_okActionPerformed(java.awt.event.ActionEvent evt) {
		this.setVisible(false);
		this.dispose();
	}

}
